Utils::StyledBar Class

class Utils::StyledBar

The StyledBar class is a panel widget for tool bars. More...

Header: #include <utils/widgets.h>

Public Functions

void addItem(const Utils::Key &id, const class QString &displayName, QWidget *widget)
void addSeparator(const Utils::Key &id)
void addSpacer(const Utils::Key &id)
void addStretch(const Utils::Key &id)
Utils::KeyList hiddenItems() const
Utils::KeyList itemOrder() const
void resetItemConfiguration()
void setHiddenItems(const Utils::KeyList &ids)
void setItemOrder(const Utils::KeyList &ids)
void setItemStretch(const Utils::Key &id, int stretch)
void setItemVisible(const Utils::Key &id, bool visible)
void setPermanentItems(const Utils::KeyList &ids)
void setSettingsKey(const Utils::Key &key)

Detailed Description

Widgets added with addItem() are laid out by the bar itself. The user can then change their order and hide them in the customization dialog that the context menu of the bar opens, except for the items passed to setPermanentItems(). Use setItemVisible() instead of QWidget::setVisible() to show or hide such items from code. In the customization dialog, the user can also add any number of separators, fixed-width spacers, and stretches. Hiding them removes them again. With setSettingsKey(), the configuration is stored in the user settings.

Like QToolBar, the bar moves the trailing items that do not fit into a popup that an extension button at its end opens. Permanent items always stay in the bar.

Member Function Documentation

void StyledBar::addItem(const Utils::Key &id, const class QString &displayName, QWidget *widget)

Adds widget with the identifier id to the end of the bar. The user sees it as displayName when configuring the bar.

void StyledBar::addSeparator(const Utils::Key &id)

Adds a separator with the identifier id to the end of the bar. The user can move and hide it in the toolbar customization dialog.

void StyledBar::addSpacer(const Utils::Key &id)

Adds a fixed-width space with the identifier id to the end of the bar. The user can move and hide it in the toolbar customization dialog.

void StyledBar::addStretch(const Utils::Key &id)

Adds a stretchable space with the identifier id to the end of the bar. The user can move it, but not hide it.

Utils::KeyList StyledBar::hiddenItems() const

Returns the identifiers of the hidden items.

See also setHiddenItems().

Utils::KeyList StyledBar::itemOrder() const

Returns the identifiers of all items in the order in which they appear in the bar, including hidden ones.

See also setItemOrder().

void StyledBar::resetItemConfiguration()

Restores the order in which the items were added and shows all of them.

void StyledBar::setHiddenItems(const Utils::KeyList &ids)

Hides the items with the identifiers ids, except for permanent ones.

See also hiddenItems().

void StyledBar::setItemOrder(const Utils::KeyList &ids)

Orders the items as given by ids. Unknown identifiers are ignored, items missing from ids are placed after their predecessor in the order in which they were added.

Separators and spacers added by the user are the exception: an unknown identifier with their prefix creates a new one, and those missing from ids are removed from the bar.

See also itemOrder().

void StyledBar::setItemStretch(const Utils::Key &id, int stretch)

Sets the stretch factor of the item id to stretch. As in QBoxLayout, once an item has a stretch factor, extra space goes to the items with one, in proportion to their factors.

void StyledBar::setItemVisible(const Utils::Key &id, bool visible)

Shows or hides the item id depending on visible. An item the user has hidden stays hidden.

void StyledBar::setPermanentItems(const Utils::KeyList &ids)

Prevents the user from hiding the items with the identifiers ids.

void StyledBar::setSettingsKey(const Utils::Key &key)

Restores the item configuration from the user settings at key and stores it there on every change. Call this after adding the items.